package com.qf.team2.netdisc.common.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author hanch
 * @since 2021.5.26
 *
 */
public class ComputationTimeUtils {
    /**
     * 将目标时间和当前时间进行计算（结果为毫秒）
     */
    public static long  computationTime(Timestamp createTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String now = sdf.format(new Date());
        String createTimeS = sdf.format(createTime);
        long nowL = 0;
        long creatTimeL = 0;
        long result=0;
        try {
            nowL = sdf.parse(now).getTime();
            creatTimeL = sdf.parse(createTimeS).getTime();
            result=nowL-creatTimeL;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }
}
